package com.kcnet.qk.controller.hdyh;

import android.view.accessibility.AccessibilityEvent;

import com.kcnet.qk.constant.Const;
import com.kcnet.qk.controller.BasePeopleController;
import com.kcnet.qk.controller.sjgl.AddNearPeopleController;
import com.kcnet.qk.util.PreferenceHelper;
import com.kcnet.qk.util.RootShell;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import cn.jesse.nativelogger.NLogger;

/**
 * Created by Administrator on 2018/7/9.
 * 养号 好友之间互相聊天
 */

public class HdyhFriendSendMsgCTR extends BasePeopleController{

    private static HdyhFriendSendMsgCTR mRongCloudInstance;

    private List<String> list;
    protected static final String TAG = "互动聊天";

    public static HdyhFriendSendMsgCTR getInstance() {
        if (mRongCloudInstance == null) {
            synchronized (HdyhFriendSendMsgCTR.class) {

                if (mRongCloudInstance == null) {
                    mRongCloudInstance = new HdyhFriendSendMsgCTR();
                }
            }
        }

        return mRongCloudInstance;
    }


    @Override
    public void doTask(AccessibilityEvent event) throws Exception {
        mType = event.getEventType();
        mClassName = (String) event.getClassName();
        if (mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals(Const.WXUI.LauncherUI)) {
            NLogger.d(TAG,"1.进入微信首页 点击 发现 按钮");
            sleepTime(2000);
            RootShell.click(43,886);

            sleepTime(1000);
            NLogger.d(TAG,"2.到达微信 点击 第一个聊天对话框");
            RootShell.click(111,125);
            NLogger.d(TAG,"3.进入对话界面 随机发送消息");
            sleepTime(2000);
            for(currentAddCount=0;currentAddCount<maxAddCount;currentAddCount++){
                RootShell.click(90,900);
                sleepTime(1000);
                int c = Random(0, list.size()-1);
                inputSayHiSentence(list.get(c));
                sleepTime(1000);
                RootShell.click(465,900);
                sleepTimedDefault();
            }
            stopTask();
        }
    }

    /**
     *
     * @param maxAddCount 默认参数
     * @param minAddTime
     * @param maxAddTime
     * @param list 回复的话语数组，可以传入特定关键字去匹配结果
     */
    public void setParms(int maxAddCount,int minAddTime,int maxAddTime,List<String> list){
        //  stopTask();
        EventBus.getDefault().post(new Boolean(true));
        PreferenceHelper.putBoolean(Const.PREF_KEY_STOP_AUTO_FLAG, true);
        this.maxAddCount = maxAddCount;
        this.minAddTime = minAddTime;
        this.maxAddTime = maxAddTime;
        this.currentAddCount = 0;
        this.list = list;
    }

}
